package ui.tempdao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import util.HibernateUtil;
import dao.EgnFixedIncome;

public class EgnFixedIncomeDao {
	private final static Logger logger = LoggerFactory.getLogger(EgnFixedIncomeDao.class);

	public static List<EgnFixedIncome> getAllEgnFixedIncome() {
		List<EgnFixedIncome> rst ;
		Session s = HibernateUtil.currentSession();
		logger.debug("Get all EgnProduct instance");
		Query qr = s.createQuery("from EgnFixedIncome" );

		try {
			rst = qr.list();
			HibernateUtil.closeSession();
			return rst;
		} catch (RuntimeException re) {
			logger.error("failed", re);
			HibernateUtil.closeSession();
			throw re;
		}
	}
	public static List<EgnFixedIncome> getAllEgnFixedIncome(int rstCount) {
		List<EgnFixedIncome> rst ;
		Session s = HibernateUtil.currentSession();
		logger.debug("Get all EgnProduct instance");
		Query qr = s.createQuery("from EgnFixedIncome" );
		qr.setMaxResults(rstCount);

		try {
			rst = qr.list();
			HibernateUtil.closeSession();
			return rst;
		} catch (RuntimeException re) {
			logger.error("failed", re);
			HibernateUtil.closeSession();
			throw re;
		}
	}

	public static EgnFixedIncome getEgnFixedIncome(String prodId) {
		EgnFixedIncome rst ;
		Session s = HibernateUtil.currentSession();
		logger.debug("Get all EgnProduct instance 11");
		
		Query qr = s.createQuery(" from EgnFixedIncome a where a.id.productId =:param"	);
		qr.setParameter("param", prodId);
		try {
			rst = (EgnFixedIncome)qr.uniqueResult();
			HibernateUtil.closeSession();
			return rst;
		} catch (RuntimeException re) {
			logger.error("failed", re);
			HibernateUtil.closeSession();
			throw re;
		}
	}
}
